package com.tem.content.controllerFront;

import com.api.manage.feign.system.SystemClientService;
import com.api.manage.pojo.content.CmsTypeBean;
import com.api.manage.pojo.system.SysBranchOfficeBean;
import com.api.manage.pojo.system.SysDepartmentBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tem.common.core.base.BaseController;
import com.tem.common.tool.result.ResultUtil;
import com.tem.content.bean.Cms1ResultUtil;
import com.tem.content.entity.CmsType;
import com.tem.content.service.ICmsContentService;
import com.tem.content.service.ICmsTypeService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/front/content/cmsType")
public class CmsTypeControllerFront extends BaseController {
    @Autowired
    private ICmsTypeService cmsTypeService;

    @Autowired
    private SystemClientService systemClientService;

    @Autowired
    private ICmsContentService cmsContentService;

    @ApiOperation(value = "列表")
    @RequestMapping("list")
    public Cms1ResultUtil<List<CmsTypeBean>> list(CmsTypeBean request, HttpServletRequest req){
        //Long[] myids = this.getMyIds(req);
        System.out.println(req.getRemoteHost()+"---------------------------");
        QueryWrapper<CmsType> wrapper = new QueryWrapper<>();
        //wrapper.lambda().eq(CmsType::getSysBranchOfficeId , myids[2]);
        wrapper.orderByDesc("seq");
        List<CmsType> entityList= cmsTypeService.list(wrapper);
        if(!entityList.isEmpty()) {
            List<CmsTypeBean> responseList = new ArrayList<>();
            entityList.forEach(it -> {
                CmsTypeBean bean = new CmsTypeBean();
                BeanUtils.copyProperties(it,bean);
                ResultUtil<SysBranchOfficeBean> sdbean = systemClientService.getSysBranchOfficeBeanById(bean.getSysBranchOfficeId());
                bean.setSysBranchOfficeIdName(sdbean.getData().getOfficeName());
                responseList.add(bean);
            });
            List<CmsTypeBean> responseList2 = cmsTypeService.getTree(responseList);
            return Cms1ResultUtil.successMy(responseList2);
        }
        return null;
    }

}
